package top.honlnk.common.config;

import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import top.honlnk.controller.time.updateDatabaseControllerTime;

@Configuration
public class QuartzConfig {
    @Bean
    public JobDetail jobDetail() {
        return JobBuilder.newJob(updateDatabaseControllerTime.class)
                .storeDurably() // 持久化
                .withIdentity("每晚八点检查数据库密钥的合法性", "定时任务") // 任务名称 任务组名
                .build();
    }

    @Bean
    public Trigger trigger() {
        String croExpression = "0 0 20 * * ? *";
        return TriggerBuilder.newTrigger()
                .forJob(jobDetail())
                .withSchedule(CronScheduleBuilder.cronSchedule(croExpression))  // 时间规则 cron表达式
                .withIdentity("八点整执行器", "定时任务") // 触发器名称 任务组名
                .build();
    }
}
